package com.lytoyo.neihanduanzi.controller;

import com.lytoyo.neihanduanzi.model.Result;
import com.lytoyo.neihanduanzi.model.query.UserIndexQuery;
import com.lytoyo.neihanduanzi.model.vo.UserSearchResponseVo;
import com.lytoyo.neihanduanzi.service.SearchService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Package:com.lytoyo.neihanduanzi.controller
 *
 * @ClassName:SearchApiController
 * @Create:2025/4/10 16:03
 **/
@RestController
@RequestMapping("/search")
public class SearchApiController {

    @Resource
    private SearchService searchService;

    /**
     * 关键词补全
     * @param keyword
     * @return
     */
    @GetMapping("/completeSuggest")
    public Result completeSuggest(@RequestParam("keyword") String keyword){
        List<String> list = searchService.completeSuggest(keyword);
        return Result.success(list);
    }

    /**
     * 查询用户信息
     * @param userIndexQuery
     * @return
     */
    @PostMapping("/user")
    public Result search(@RequestBody UserIndexQuery userIndexQuery){
        UserSearchResponseVo search = searchService.search(userIndexQuery);
        return Result.success(search);
    }

    /**
     * 综合分页查询，一次查询十条博客
     * 如果是首次查询，需要多查询一位用户，即第一次查询11条数据
     * 后面查询不包括用户
     * @param keyword
     * @return
     */

    @GetMapping("/comprehensive")
    public Result comprehensiveSearch(@RequestParam("keyword")String keyword,@RequestParam("pageNo") Integer pageNo,@RequestParam("pageSize")Integer pageSize){
        Map<String,Object> map = searchService.comprehensiveSearch(keyword,pageNo,pageSize);
        return Result.success(map);
    }
}
